public class Main {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();//计算开始的时间
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();//计算结束的时间
        System.out.println(end - start);
        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static void main10(String[] args) {
//        String s1 = "My name is LiHua";
//        System.out.println(s1.substring(2));// name is LiHua
//        System.out.println(s1.substring(0,8));//My name

            String s = "hello";
            s += " world";
            System.out.println(s); // 输出：hello world
    }

    public static void main9(String[] args) {
        String str = "hello world hello bit" ;
        String[] result = str.split(" ",2) ;
        for(String s: result) {
            System.out.println(s);
        }
        String str1 = "hello world hello bit" ;
        String[] result1 = str.split(" ") ; // 按照空格拆分
        for(String s: result) {
            System.out.println(s);
        }

//        String str = "hello.world" ;
//        System.out.println(str.replaceAll("\\.","\\\\"));
//        System.out.println(str.replaceAll("l", "_"));
//        System.out.println(str.replaceFirst("l", "_"));

//        String s1=String.format("%d-%d-%d",2025,9,14);
//        System.out.println(s1);
    }

    public static void main8(String[] args) {
        String str1 = new String("123zhangsan@^");
        char[] ch = str1.toCharArray();
        System.out.println(ch);
    }

    public static void main7(String[] args) {
            String s1 = "hello";
            String s2 = "HELLO";
            //小写转大写
            System.out.println(s1.toUpperCase());//————》HELLO
            //大写转小写
            System.out.println(s2.toLowerCase());//————》hello
    }

    public static void main6(String[] args) {
        String str1 =String.valueOf(1234);
        String str2 =String.valueOf(12.34);
        String str3 =String.valueOf(true);
        String str4 =String.valueOf(new Student("zhangsan",13));
//        String str5 =String.valueOf("abc");

        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(str4);
//        System.out.println(str5);
    }

    public static void main5(String[] args) {
        String s1="abc";
        String s2="Abc";

        System.out.println(s1.compareToIgnoreCase(s2));//返回0
    }

    public static void main4(String[] args) {
        String s1="abc";
        String s2="ac";
        String s3="abc";
        String s4="abcdef";

        System.out.println(s1.compareTo(s2));//"abc"与"ac"的比较，遇到相同字符就继续向下比较；'b'比'c'小1--》返回-1
        System.out.println(s1.compareTo(s3));//返回0
        System.out.println(s1.compareTo(s4));//返回-3

        String s = "aaabbbcccaaabbbccc";
        System.out.println(s.charAt(3)); // 'b'
        System.out.println(s.indexOf('c')); // 6
        System.out.println(s.indexOf('c', 10)); // 15
        System.out.println(s.indexOf("bbb")); // 3
        System.out.println(s.indexOf("bbb", 10)); // 12
        System.out.println(s.lastIndexOf('c')); // 17
        System.out.println(s.lastIndexOf('c', 10)); // 8
        System.out.println(s.lastIndexOf("bbb")); // 12
        System.out.println(s.lastIndexOf("bbb", 10)); // 3
    }

    public static void main3(String[] args) {
        int a=10;
        int b=20;
        int c=10;

        System.out.println(a==b);
        System.out.println(a==c);

        // 对于引用类型变量，==比较两个引用变量引用的是否为同一个对象
        String s1 = new String("hello");
        String s2 = new String("hello");
        String s3 = new String("world");
        String s4 = s1;
        System.out.println(s1 == s2); // false
        System.out.println(s2 == s3); // false
        System.out.println(s1 == s4); // true

        //s1、s2、s3引用的是三个不同的对象
        System.out.println(s1==s2);//false
        System.out.println(s1==s3);//false
        System.out.println(s1==s4);//true

        System.out.println(s1.equals(s2));//因为两个对象的内容一样，所以认为s1和s2相同——》true
        System.out.println(s1.equals(s3));//false

    }

    public static void main2(String[] args) {
        //基于数组的性质，可以求得字符串的长度
        String str1 = "Hello";
        System.out.println(str1.length());//使用length()求长
        System.out.println(str1.isEmpty());//判断str的对象是否为空（长度为0），是则返回true，否返回false

        System.out.println("hello".length());
    }


    public static void main1(String[] args) {
//        String str1 = "abc";//方式1
//
//        String str2 = new String("zhangsan");//方式2
//
//        char[] ch = {'l', 'i', 's', 'i'};//方式3
//        String str3 = new String(ch);
    }


//        String str1 = String.valueOf(true);
//        System.out.println(str1);
//        String str2 = String.valueOf(new Student("Hanmeimei", 18));
//        System.out.println(str2);
//        String s = String.format("%d-%d-%d", 2019, 9,14);
//        System.out.println(s);
//        Student s1=new Student("lisi",17);
//        Student s2=s1;
//        System.out.println(s1);//不是根据引用本身打印的，而是引指向的对象
//        System.out.println(s2);
//        String str = "hello world hello bit" ;
//        String[] result = str.split(" ",2) ;
//        for(String s1: result) {
//            System.out.println(s1);

//        String str3 = "hello world";
//        System.out.println(str3.replaceFirst("l","j"));
//    }

}